from sqlmodel import Field, SQLModel
# from pydantic import BaseModel, Field
from datetime import datetime

class SwapRecordBase(SQLModel):
    """WaveUp兑换记录基础模型"""
    productPairId: str = Field(default="", index=True, description="交易对编码")
    fromProductId: str = Field(default="", description="换入藏品ID")
    fromAmount: float = Field(default=0.0, description="换入藏品数量")
    toProductId: str = Field(default="", description="换出藏品ID")
    toAmount: float = Field(default=0.0, description="换出藏品数量")
    slippage: float = Field(default=0.0, description="滑点比例")
    profitAmount: float = Field(default=0.0, description="套利收益")
    exchangeType: int = Field(default=0, description="兑换类型 0:A->B 1:B->A")
    dealValue: float = Field(default=0.0, description="成交金额")
    fee: float = Field(default=0.0, description="手续费（平台手续费+流动性池手续费）")

class SwapRecordCreate(SwapRecordBase):
    """WaveUp兑换记录创建模型"""
    swapOrderNo: str = Field(default="", index=True, description="兑换订单号")
    uid: int = Field(default=0, description="用户ID")

class SwapRecordUpdate(SQLModel):
    """WaveUp兑换记录更新模型"""
    id: int = Field(default=0, description="兑换记录ID")
    fromAmount: float = Field(default=0.0, description="换入藏品数量")
    toAmount: float = Field(default=0.0, description="换出藏品数量")
    exchangeType: int = Field(default=0, description="兑换类型 0:A->B 1:B->A")
    dealValue: float = Field(default=0.0, description="成交金额")
    fee: float = Field(default=0.0, description="手续费（平台手续费+流动性池手续费）")
    wpSwapId: str = Field(default="", index=True, description="waveup兑换记录ID")
    status: int = Field(default=0, description="兑换状态 0:待处理 1:已完成 2:兑换失败")

class SwapRecordOut(SwapRecordBase):
    """WaveUp兑换记录输出模型"""
    id: int = Field(default=0, description="兑换记录ID")
    createTime: datetime = Field(default_factory=datetime.now, description="创建时间")

    model_config = {
        "json_encoders": {
            datetime: lambda v: v.strftime("%Y-%m-%d %H:%M:%S")
        }
    }